//
//  RSASignViewController.m
//  RSA加密
//
//  Created by liaowentao on 17/7/25.
//  Copyright © 2017年 Haochuang. All rights reserved.
//

#import "RSASignViewController.h"
#import "HBRSAHandler.h"

@interface RSASignViewController ()
@property (weak, nonatomic) IBOutlet UILabel *signedString;
@property (weak, nonatomic) IBOutlet UILabel *unsignedString;

@property (weak, nonatomic) IBOutlet UITextField *inputTextField;
@end

@implementation RSASignViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)buttonAction:(UIButton *)sender {
    
    NSString* private_key_string = @"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCQ0bwfi9MbiojSNzhPrWtE/lJq5tTZu1vK9XIxZf+T3o7S6+4i9FLo+CXa+8HOqrrnk9YBG7XbLfIKfpkIMgmP327pSXMDjgW0nDG3Qy+NW3tn4N8q4MQZGh00xYFXfhqMFk5FKCx3OIzgvrNLmdf92Qb1qSs0RQdplT5pkNfpkXbd84HBAmtVo+nLvnX77qqHLP+EA8xyp42ISMfTRLRgQxSlXmnE2t4FEyl5Z7bjO1U295Cyzo5Fl1/kdss7saEJJkKi3MP9DI7RAZV/qw/4fR2Y0OUzsILAf+0Q0hldAcEmeAs0GtDv8HwZyCWO69GyqjikJJosVy3RQTAD/vuTAgMBAAECggEAeQkyB9OfLyeLztYkFEPGobVFQN+ICioTP///3tV21ClwiUxyjXhSSzAKw4kipA4BhEcE14xHY9Z0sty4Hidj4oFFe2jN3ay3jAn3a0mV1rkc3OcO3hFZE/nFazOfNHbKzUZfSGGZOFNlOvlndMoxwZG/xVYMK/V9insX3LcYHbcYBri2+xJzRew+8xJBocaDFIZni4pbtqVDIlQtrigmtf49shp5ySOiNLT95imzwVN7UJvEJumVWZioTEFv+6CD/dXxGaslhOQDB0Pa5NKVU34pkZPUNJj6sW0Gc3KQPDhaVU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BSyZbBIYKCBJrx0YsKsrx17LeaRBqk4Xy1qCfvCyixZeYKzlXj0l+LUofEBmPiKvhONVPr1RlSGYLMbIoTKBbI6zSoSIIhYl1d2WO5/EGQ1G+UZo4D+xBW+g/jlEkp0Hqb4kjj674N34SFemz/ljgD5tt6O3aYWHX7NOlZxgogRWrwWkI5ipTSD8tWiNQjfU6FOSYFad31n6SceOTTOUfiXyWkjwNsSXn6ADSkQIDAQAB";
    
    HBRSAHandler* handler = [HBRSAHandler new];
    [handler importKeyWithType:KeyTypePrivate andkeyString:private_key_string];
    [handler importKeyWithType:KeyTypePublic andkeyString:public_key_string];
    
    NSString *ppp =@"appId=ios&content={\"secret\":\"ioskkkk\",\"appId\":\"ios\"}&service=token.create&sign_type=RSA2&timestamp=1533307483586";
    NSString* sig = [handler signString:_inputTextField.text];
    _signedString.text = [NSString stringWithFormat:@"签名后：%@",sig];
    BOOL a = [handler verifyString:_inputTextField.text withSign:sig];
    if (a) {
        _unsignedString.text = @"验签成功";
    }else{
        _unsignedString.text = @"验签失败";
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
